﻿
//
//
//

namespace Microsoft.OpenTurf.Silverlight.Shared
{
    using System;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;

    [FeedItemTranslator(typeof(TwitterTranslator))]
    public class TwitterFeedItem
    {
        #region
        public TwitterFeedItem()
        {
        }
        #endregion

        #region Properties
        private string _id;
        public string id
        {
            get { return _id; }
            set { _id = value; }
        }

        private string _from_user;
        public string from_user
        {
            get { return _from_user; }
            set { _from_user = value; }
        }

        private string _text;
        public string text
        {
            get { return _text; }
            set { _text = value; }
        }

        public string link
        {
            get { return string.Format("http://www.twitter.com/{0}/status/{1}", from_user, id); }
        }

        private string _profile_image_url;
        public string profile_image_url
        {
            get { return _profile_image_url; }
            set { _profile_image_url = value; }
        }

        private string _location;
        public string location
        {
            get { return _location; }
            set { _location = value; }
        }

        public List<MapPoint> MapPoints
        {
            get { return CreateMapPoints(); }
        }

        private string _created_at;
        public string created_at
        {
            get { return _created_at; }
            set { _created_at = value; }
        }
        #endregion
        #region Methods
        public List<MapPoint> CreateMapPoints()
        {
            List<MapPoint> points = new List<MapPoint>();

            foreach (Match geoCode in Regex.Matches(location, AppGlobals.GEO_CODE_PATTERN))
            {
                string[] pair = geoCode.Value.Split(new char[] { ',' });
                double latitude = Double.Parse(pair[0]);
                double longitude = Double.Parse(pair[1]);

                MapPoint point = new MapPoint(latitude, longitude);

                points.Add(point);
            }
            return points;
        }
        #endregion
    }
}